package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.DengjiEmployeeAccess;
import com.amsp.oa.oademo.mapper.DengjiEmployeeAccessMapper;
import com.amsp.oa.oademo.service.DengjiEmployeeAccessService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.util.List;

@Service
public class DengjiEmployeeAccessServiceImpl extends ServiceImpl<DengjiEmployeeAccessMapper, DengjiEmployeeAccess> implements DengjiEmployeeAccessService {

    @Override
    public IPage<DengjiEmployeeAccess> getPage(Integer current, Integer size, String name, String employeeId, String date) {
        Page<DengjiEmployeeAccess> page = new Page<>(current, size);
        LambdaQueryWrapper<DengjiEmployeeAccess> wrapper = new LambdaQueryWrapper<>();
        
        if (StringUtils.hasText(name)) {
            wrapper.like(DengjiEmployeeAccess::getName, name);
        }
        if (StringUtils.hasText(employeeId)) {
            wrapper.like(DengjiEmployeeAccess::getEmployeeId, employeeId);
        }
        if (StringUtils.hasText(date)) {
            wrapper.eq(DengjiEmployeeAccess::getDate, LocalDate.parse(date));
        }
        
        wrapper.orderByDesc(DengjiEmployeeAccess::getCreateTime);
        return page(page, wrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateBatch(List<DengjiEmployeeAccess> records) {
        return super.saveOrUpdateBatch(records);
    }
} 